<?php

/**
 * ECSHOP 管理中心优惠活动管理
 * ============================================================================
 * * 版权所有 2005-2012 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: favourable.php 17217 2011-01-19 06:29:08Z liubo $
 */
 
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

/*------------------------------------------------------ */
//-- 活动列表页
/*------------------------------------------------------ */

if ($_REQUEST['act'] == 'list')
{
    admin_priv('users_manage');

    $time1=gmtime();
    $date1=local_date('Y-m-d',$time1);
    $date2=local_date('Y-m-d',$time1);
    $stm1=strtotime($date1);
    $stm2=strtotime($date2)+3600*24;

    $promote_start_date=$_POST['promote_start_date']?$_POST['promote_start_date']:$date1;
    $promote_end_date=$_POST['promote_end_date']?$_POST['promote_end_date']:$date2;

    if($_POST['promote_start_date'])
    {
      $stm1=strtotime($_POST['promote_start_date']);
      $stm2=strtotime($_POST['promote_end_date'])+3600*24;
    }
    if($promote_start_date>$promote_end_date)
    {
        sys_msg('时间区间错误。');exit;
    }


    /* 模板赋值 */
    $smarty->assign('ur_here',     '旅行社统计');


    $smarty->assign('promote_start_date',$promote_start_date);
    $smarty->assign('promote_end_date',$promote_end_date);
   
    
    $data=mshop_sum();
    $order=order_sum($stm1,$stm2);

    $sum_profitbytime=mshop_frozen_sum($stm1,$stm2);

    $smarty->assign('data',$data);
    $smarty->assign('order',$order);
    $smarty->assign('sum_profitbytime',$sum_profitbytime);

    $smarty->display('mshop_count.htm');
}
//店铺统计
   function mshop_sum()
   {
        $sql = "SELECT count(*) as num,sum(sum_amount) as sum_amount,sum(frozen_profit) as sum_frozen,sum(lock_profit) as sum_lock"
               .",sum(sum_profit) as sum_txprofit,sum(sum_cash_amount) as sum_cash "
                ."FROM " . $GLOBALS['ecs']->table('mshop');

        $row=$GLOBALS['db']->getRow($sql);

        $row['profit']= $row['sum_txprofit']+ $row['sum_frozen']+ $row['sum_lock']+ $row['sum_cash'];//累积佣金总额
        return $row;
   }
//已付款订单统计
   function order_sum($time1,$time2)
   {

     $sql=" select count(*) as num,sum( goods_amount + tax + shipping_fee +insure_fee +pay_fee +pack_fee +card_fee ) AS total_fee"
         ." from ".$GLOBALS['ecs']->table('order_info')." where mshop_id!=0 and  pay_status=2 and order_status=5";

     $row=$GLOBALS['db']->getRow($sql);

     $where='';

     $where=" and pay_time>='$time1' and pay_time<='$time2'";    
      $sql=" select count(*) as num,sum( goods_amount + tax + shipping_fee +insure_fee +pay_fee +pack_fee +card_fee ) AS total_fee"
     ." from ".$GLOBALS['ecs']->table('order_info')." where mshop_id!=0 and pay_status=2 and order_status=5 ".$where;
      $row2=$GLOBALS['db']->getRow($sql);

      $row['tnum']=$row2['num'];
      $row['ttotal_fee']=$row2['total_fee']?$row2['total_fee']:'0.00';
      return $row;
   }
  //佣金统计
   function mshop_frozen_sum($time1,$time2)
   {
     $where='';

     $where="  and ctime>='$time1' and ctime<='$time2'";   
     

      $sql="select sum(frozen_profit) as sum_frozen from ".$GLOBALS['ecs']->table('mshop_frozen_profit')." where status!=2 ".$where;
      $row=$GLOBALS['db']->getRow($sql);
      $sum=$row['sum_frozen']?$row['sum_frozen']:'0.00';

      // $sql="select sum(frozen_profit) as sum_frozen from ".$GLOBALS['ecs']->table('mshop_frozen_profit')." where status=1 ".$where;
      // $row2=$GLOBALS['db']->getRow($sql);
      // $result['sum_unfrozen']=$row2['sum_frozen']?$row2['sum_frozen']:'0.00';

       return $sum;
   }



?>